<!--
 ~ Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 ~
 ~ WSO2 Inc. licenses this file to you under the Apache License,
 ~ Version 2.0 (the "License"); you may not use this file except
 ~ in compliance with the License.
 ~ You may obtain a copy of the License at
 ~
 ~    http://www.apache.org/licenses/LICENSE-2.0
 ~
 ~ Unless required by applicable law or agreed to in writing,
 ~ software distributed under the License is distributed on an
 ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 ~ KIND, either express or implied.  See the License for the
 ~ specific language governing permissions and limitations
 ~ under the License.
 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Lifecycle Configuration - User Guide</title>
  <link href="../../admin/css/documentation.css" rel="stylesheet" type="text/css" media="all" />
</head>

<body>
<p></p>
<h1>Configuring and Managing Lifecycles</h1>
<p></p>
<ul>
    <li><a href="#addLCconfig">Adding a lifecycle configuration</a></li>
    <li><a href="#editingLCconfig">Editing a lifecycle configuration</a></li>
    <li><a href="#deleteLCconfig">Deleting a lifecycle configuration</a></li>
    <li><a href="#searchingLC">Searching for resources/collections with lifecycles</a></li>
    <li><a href="#LCconfig">Lifecycle Configuration</a></li>
</ul>
<p></p>
<p>In the navigator under "Extensions" click on "Lifecycles". A list of available lifecycles is shown. </p>
<p><img src="images/view_lc.png" alt="" width="749px"/></p>
<p></p>

<a name="addLCconfig"></a>
<h2>Adding a lifecycle configuration</h2>
<p>In the above lifecycle configuration page, click on "Add Lifecycle". A configuration page with a sample lifecycle configuration is shown.
   Click on save to save the configuration or cancel to return to available lifecycle configuration list.</p>

<a name="editingLCconfig"></a>
<h2>Editing an existing lifecycle configuration</h2>
<p>Click on corresponding "Edit" link found under each lifecycle configuration, from lifecycle configuration list.
   A configuration page with the lifecycle configuration is shown.</p>
<p><img src="images/add_edit_lc.png" alt="" width="749px"/></p>
<p>Note that, if the lifecycle configuration is in use, editing is not allowed</p>
<p><img src="images/cantedit.png" alt="" width="749px"/></p>

<a name="deleteLCconfig"></a>
<h2>Deleting an existing lifecycle configuration</h2>
<p>Click on corresponding "Delete" link found under each lifecycle configuration, from lifecycle configuration list.
   A confirmation prompt is shown. Note that, if the lifecycle configuration is in use, deletion is not allowed.</p>

<a name="searchingLC"></a>
<h2>Searching for resources/collections with lifecycles</h2>
<p>You can search for resources/collections with any lifecycle by clicking "Find Resources/Collections With Lifecycles".
To search for resources/collections having a specific lifecycle, click on the corresponding "Find Usage" button.</p>

<a name="LCconfig"></a>
<h2>Lifecycle Configuration</h2>
<p>Following is the template of the life cycle configuration. In the configuration, the xml element structure should strictly followed.
The configuration elements and their usage is defined inline with the elements. </p>
<p>
<pre>
<strong>&lt;aspect name="" class="org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle"&gt;</strong>
    &lt;!-- name - used to give the name of the life cycle
         class -  gives the default life cycle class. This can be any class that extends an aspect --&gt;
<strong>    &lt;configuration type=""&gt;      </strong>
        &lt;!--type - can have either 'literal' or 'resource' as values --&gt;
       <strong> &lt;lifecycle&gt;
            &lt;scxml xmlns="http://www.w3.org/2005/07/scxml"
                   version="1.0"
                   initialstate=""&gt;</strong>
                &lt;!--initialstate - defines the starting state of the life cycle and can not be null or empty--&gt;
            <strong>    &lt;state id=""&gt;                              </strong>
                    &lt;!-- state element - defines a life cycle state
                    id -  defines the name of the state--&gt;
                    <strong>&lt;datamodel&gt;                                              </strong>
                        &lt;!--contains 4 data elements that defines check items, transition validations, transition permissions
                        and transition scripts--&gt;
                        <strong>&lt;data name="checkItems"&gt;                    </strong>
                            &lt;!--name - defines that this element contains the set of check items. It is required to be
                            set to 'checkItems'--&gt;
                          <strong>  &lt;item name="" forEvent=""&gt;     </strong>
                                &lt;!--name - defines the check item name
                                    forEvent - de fines the set of transitions that this check item is required. Accepts a
                                    ',' separated list--&gt;
                              <strong>  &lt;permissions&gt;
                                    &lt;permission roles=""/&gt;                                    </strong>
                                    &lt;!--roles - defines the set of roles that has the ability to check/un-check this check item--&gt;
                             <strong>   &lt;/permissions&gt;
                                &lt;validations&gt;
                                    &lt;validation forEvent="" class=""&gt;                 </strong>
                                        &lt;!--forEvent - defines the event that the custom validation should be done
                                          class - defines the full qualified name of the custom validations class --&gt;
                                <strong>        &lt;parameter name="" value=""/&gt;</strong>
                                        &lt;!--name - defines the custom parameter name
                                           value - defines the custom parameter value--&gt;
                            <strong>        &lt;/validation&gt;
                                &lt;/validations&gt;
                            &lt;/item&gt;
                        &lt;/data&gt;
                        &lt;data name="transitionValidation"&gt;         </strong>
                            &lt;!--name - defines that this element contains the set of transition validations. It is required to be
                            set to 'transitionValidation'--&gt;
                           <strong> &lt;validation forEvent="" class=""&gt;
                                &lt;parameter name="" value=""/&gt;
                            &lt;/validation&gt;
                        &lt;/data&gt;
                        &lt;data name="transitionPermission"&gt;</strong>
                            &lt;!--name - defines that this element contains the set of transition permissions. It is required to be
                            set to 'transitionPermission'--&gt;
                         <strong>   &lt;permission forEvent="" roles=""/&gt;
                        &lt;/data&gt;
                        &lt;data name="transitionScripts"&gt;                                               </strong>
                            &lt;!--name - defines that this element contains the set of transition scripts. It is required to be
                            set to 'transitionScripts'--&gt;
                         <strong>   &lt;js forEvent=""&gt;                                         </strong>
                                &lt;!--forEvent - defines the event that this script block will execute--&gt;
                           <strong>     &lt;console function=""&gt;                       </strong>
                                    &lt;!--function - defines the name of the function--&gt;
                               <strong>     &lt;script type="text/javascript"&gt;</strong>
                                        &lt;!--contains the script--&gt;
                                <strong>    &lt;/script&gt;
                                &lt;/console&gt;
                                &lt;server function=""&gt;
                                    &lt;script type="text/javascript"&gt;&lt;/script&gt;
                                &lt;/server&gt;
                            &lt;/js&gt;
                        &lt;/data&gt;
                    &lt;/datamodel&gt;
                    &lt;transition event="" target=""/&gt;</strong>
                    &lt;!--event - defines the name of the transition event
                        target - defines the next state of the transition--&gt;
             <strong>   &lt;/state&gt;
            &lt;/scxml&gt;
        &lt;/lifecycle&gt;
    &lt;/configuration&gt;
&lt;/aspect&gt; </strong>
</pre>
</p>
<p>
    The life cycle configuration give the user the ability to define custom validations. This can be done by providing
    a custom class for the "class" parameter in the following element. The "class" attribute in the above element should
    be filled with the full qualified name of the custom class.
    Eg:- <strong>org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle</strong>
    </p>
<p>
    <pre>
              &lt;validation forEvent="" class=""&gt;
                  &lt;parameter name="" value=""/&gt;
              &lt;/validation&gt;
    </pre>
</p>
<p>
     The custom class has to implement the CustomValidations interface which has the following structure. The values in
    the parameter elements are passed to the init method of the custom class at runtime.
</p>
<p>
    <pre>
    public interface CustomValidations {
        void init(Map parameterMap);
        boolean validate(RequestContext context);
    }
</pre>
</p>
</body>
</html>
